<script setup>
import { getTeacherHoursStatisticsApi } from '@/api/user';
import MyTable from '@/components/MyTable.vue'
import { onMounted, ref } from 'vue';
const data = ref([
    {
        "name"  : "周新刚",
        "Jan-24": "8.5",
        "Feb-24": "3.5",
        "Mar-24": "8.5",
        "Apr-24": "9",
        "May-24": "10.5",
        "Jun-24": "6",
        "Jul-24": "9",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total" : "46"
    },
    {
        "name": "魏文雅",
        "Jan-24": "13",
        "Feb-24": "6",
        "Mar-24": "19",
        "Apr-24": "14",
        "May-24": "18",
        "Jun-24": "13",
        "Jul-24": "7",
        "Aug-24": "2",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "83"
    },
    {
        "name": "袁立柱",
        "Jan-24": "10",
        "Feb-24": "6",
        "Mar-24": "15",
        "Apr-24": "12.5",
        "May-24": "13",
        "Jun-24": "10",
        "Jul-24": "13",
        "Aug-24": "1.5",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "66.5"
    },
    {
        "name": "周昊",
        "Jan-24": "7",
        "Feb-24": "3",
        "Mar-24": "9.5",
        "Apr-24": "7.5",
        "May-24": "10.5",
        "Jun-24": "9.5",
        "Jul-24": "9",
        "Aug-24": "1",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "47"
    },
    {
        "name": "万利",
        "Jan-24": "8",
        "Feb-24": "4",
        "Mar-24": "14.5",
        "Apr-24": "9.5",
        "May-24": "12",
        "Jun-24": "11",
        "Jul-24": "10",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "59"
    },
    {
        "name": "艾军",
        "Jan-24": "0",
        "Feb-24": "0",
        "Mar-24": "6",
        "Apr-24": "8",
        "May-24": "4",
        "Jun-24": "9.5",
        "Jul-24": "7.5",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "27.5"
    },
    {
        "name": "李亚",
        "Jan-24": "5.5",
        "Feb-24": "4.5",
        "Mar-24": "11",
        "Apr-24": "9.5",
        "May-24": "13",
        "Jun-24": "8",
        "Jul-24": "9",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "51.5"
    },
    {
        "name": "施重凌",
        "Jan-24": "3",
        "Feb-24": "4",
        "Mar-24": "5.5",
        "Apr-24": "5.5",
        "May-24": "6.5",
        "Jun-24": "6",
        "Jul-24": "8",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "30.5"
    },
    {
        "name": "苏强",
        "Jan-24": "1",
        "Feb-24": "0",
        "Mar-24": "3",
        "Apr-24": "0",
        "May-24": "1",
        "Jun-24": "1",
        "Jul-24": "1",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "6"
    },
    {
        "name": "盛翔",
        "Jan-24": "0",
        "Feb-24": "0",
        "Mar-24": "4.5",
        "Apr-24": "5",
        "May-24": "7",
        "Jun-24": "11.5",
        "Jul-24": "9",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "28"
    },
    {
        "name": "马利坚",
        "Jan-24": "0",
        "Feb-24": "0",
        "Mar-24": "3",
        "Apr-24": "6",
        "May-24": "6.5",
        "Jun-24": "7.5",
        "Jul-24": "4",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "23"
    },
    {
        "name": "王秀芸",
        "Jan-24": "1",
        "Feb-24": "0",
        "Mar-24": "0.5",
        "Apr-24": "0",
        "May-24": "0",
        "Jun-24": "1",
        "Jul-24": "0",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "2.5"
    },
    {
        "name": "徐新宇",
        "Jan-24": "0",
        "Feb-24": "1",
        "Mar-24": "3",
        "Apr-24": "2",
        "May-24": "2",
        "Jun-24": "8",
        "Jul-24": "6.5",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "16"
    },
    {
        "name": "赵晓云",
        "Jan-24": "0",
        "Feb-24": "0",
        "Mar-24": "0",
        "Apr-24": "1",
        "May-24": "2",
        "Jun-24": "2",
        "Jul-24": "2.5",
        "Aug-24": "0",
        "Sep-24": "0",
        "Oct-24": "0",
        "Nov-24": "0",
        "Dec-24": "0",
        "total": "5"
    }
])
const statisticalYear = ref(2024)
const cutOffMonth = ref(6)
async function getTeacherHoursStatistics() {
  const res = await getTeacherHoursStatisticsApi(statisticalYear.value)
  data.value = res
  const monthMap = new Map()
  monthMap.set(1,'jan')
  monthMap.set(2,'feb')
  monthMap.set(3,'mar')
  monthMap.set(4,'apr')
  monthMap.set(5,'may')
  monthMap.set(6,'jun')
  monthMap.set(7,'jul')
  monthMap.set(8,'aug')
  monthMap.set(9,'sep')
  monthMap.set(10,'oct')
  monthMap.set(11,'nov')
  monthMap.set(12, 'dec')
  data.value.forEach((item) => {
    let total = 0
    for (let i = 1; i <= cutOffMonth.value; i++) {
      total += item[monthMap.get(i)]
    }
    item.total = total
  })

}

onMounted(async () => {
  await getTeacherHoursStatistics()
})
const labels = ref([
  {key:"姓名"   ,value:"name"  },
  {key:"jan" ,value:"jan"},
  {key:"feb" ,value:"feb"},
  {key:"mar" ,value:"mar"},
  {key:"apr" ,value:"apr"},
  {key:"may" ,value:"may"},
  {key:"jun" ,value:"jun"},
  {key:"jul" ,value:"jul"},
  {key:"aug" ,value:"aug"},
  {key:"sep" ,value:"sep"},
  {key:"oct" ,value:"oct"},
  {key:"nov" ,value:"nov"},
  {key:"dec" ,value:"dec"},
  {key:"截止2024-06合计"  ,value:"total"},
])
</script>

<template>
  <div class="ps-container">
    <div class="title">
      <h3>培训老师统计({{ statisticalYear }})</h3>
    </div>
    <MyTable :data="data" :labels="labels" :op="false" :select="false" :paging="false"></MyTable>

  </div>
</template>

<style lang="less" scoped>
.ps-container {
  background-color: #fff;
  padding: 20px;
  h3 {
    font-weight: normal;
  }
  .title {
    margin-bottom: 20px;
  }
}
</style>
